package cn.edu.scau.cmi.xiehaizhou.composite.consistent;

import java.util.List;

import cn.edu.scau.cmi.xiehaizhou.composite.consistent.Organization;
import cn.edu.scau.cmi.xiehaizhou.composite.consistent.OrganizationOrPerson;
import cn.edu.scau.cmi.xiehaizhou.composite.consistent.Person;

public class Organization extends OrganizationOrPerson{
	//构造函数
		public Organization()
		{
			this.name = "新建组织";
			fatherOrganization = null;
		}
		public Organization(String name, Organization father)
		{
			this.name = name;
			fatherOrganization = father;
		}
		
		@Override
		public boolean AddPerson(String name)
		{
			if(childrenList!=null)
			for (OrganizationOrPerson OorP : childrenList) {
				if(OorP.getName().equals(name))
					return false;
			}
			Person child =  new Person(name,this);
			childrenList.add(child);
			return true;
		}
		@Override
		public boolean AddOrganization(String name)
		{
			if(childrenList!=null)
			for (OrganizationOrPerson OorP : childrenList) {
				if(OorP.getName().equals(name))
					return false;
			}
			Organization child = new Organization(name,this);
			childrenList.add(child);
			return true;
		}
		@Override
		public void Delete(String name)
		{
			if(childrenList!=null)
			for (OrganizationOrPerson OorP : childrenList) {
				if(OorP.getName().equals(name))
				{
					childrenList.remove(OorP);
					break;
				}
			}
		}
		@SuppressWarnings("null")
		@Override
		public List<String> getChildren()
		{
			List<String> childrenStrings = null;
			if(childrenList!=null)
			for (OrganizationOrPerson OorP : childrenList) {
				childrenStrings.add(OorP.getName());
			}
			return childrenStrings;
		}
}
